﻿using UnityEngine;
using System.Collections.Generic;

namespace WentStateMachine
{
    public class ControllerForAnimator : IStateMachineController
    {
        private Animator animator;

        public ControllerForAnimator(Animator animator)
        {
            this.animator = animator;
        }

        public IStateInfo GetCurrentStateInfo(int layerIndex)
        {
            return new StateInfoForAnimator(animator.GetCurrentAnimatorStateInfo(layerIndex));
        }

        public object GetGlobalParam(string name)
        {
            var container = animator.gameObject.GetComponent<GlobalParamsContainer>();
            return container.GetGlobalParam(name);
        }

        public void Play(string stateName)
        {
            animator.Play(stateName);
        }

        public void Play(string stateName, int layer)
        {
            animator.Play(stateName, layer);
        }

        public void Play(int stateNameHash)
        {
            animator.Play(stateNameHash);
        }

        public void Play(int stateNameHash, int layer)
        {
            animator.Play(stateNameHash, layer);
        }

        public void SetBool(string name, bool value)
        {
            animator.SetBool(name, value);
        }

        public void SetBool(int id, bool value)
        {
            animator.SetBool(id, value);
        }

        public void SetFloat(int id, float value)
        {
            animator.SetFloat(id, value);
        }

        public void SetFloat(string name, float value)
        {
            animator.SetFloat(name, value);
        }

        public void SetGlobalParam(string name, object param)
        {
            var container = animator.gameObject.GetComponent<GlobalParamsContainer>();
            if (!container)
                container = animator.gameObject.AddComponent<GlobalParamsContainer>();

            container.SetGlobalParam(name, param);
        }

        public void SetInteger(int id, int value)
        {
            animator.SetInteger(id, value);
        }

        public void SetInteger(string name, int value)
        {
            animator.SetInteger(name, value);
        }

        public void SetTrigger(int id)
        {
            animator.SetTrigger(id);
        }

        public void SetTrigger(string name)
        {
            animator.SetTrigger(name);
        }

        public void Start()
        {
            animator.gameObject.SetActive(true);
        }

        public void Stop()
        {
            animator.gameObject.SetActive(false);
        }
    }
}
